<?php
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);
$db_name="miniglider";  
 
$table_name="miniglider";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());  
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `miniglider`");
$dateTime = date("Y-m-d",strtotime("-1 day"));

    //$deviceid = mysql_fetch_array($deviceid_query);
    //while($deviceid[deviceid])

while($everylogdate = mysql_fetch_array($logdate))
{
var_dump($everylogdate[date]);
  $deviceid_query = mysql_query("SELECT  DISTINCT deviceid FROM `miniglider` WHERE IAP1 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union 

        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP2 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP3 >0  and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP4 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP5 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' union
        SELECT  DISTINCT deviceid FROM `miniglider` WHERE  IAP6 >0 and  Jailbreak = '0' and date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' ");

  while($deviceid = mysql_fetch_array($deviceid_query)) {


     mysql_query("INSERT INTO weekPay (deviceid,date) 
                    VALUES('$deviceid[deviceid]','$everylogdate[date]')") or die(mysql_error());
}

 
  
}

?>